package com.carlinfo.stu_ques.demo.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.carlinfo.stu_ques.demo.dao.IDynastyDao;
import com.carlinfo.stu_ques.demo.dao.IHuLuWaDao;
import com.carlinfo.stu_ques.demo.dao.impl.DynastyDaoImpl;
import com.carlinfo.stu_ques.demo.dao.impl.HuLuWaDaoImpl;
import com.carlinfo.stu_ques.demo.pojo.Dynasty;
import com.carlinfo.stu_ques.demo.pojo.HuLuWa;
import com.carlinfo.stu_ques.demo.service.IDemoService;
import com.carlinfo.stu_ques.question.dao.impl.QuestionDaoImpl;

public class DemoServiceImpl implements IDemoService
{
	private IDynastyDao dynastyDao = new DynastyDaoImpl();
	private IHuLuWaDao huluwaDao = new HuLuWaDaoImpl();
	@Override
	public int saveOneDynastyService(Dynasty dynasty)
	{
		/* 目前情况下,单表操作,只调用Dao的方法即可,
		 * 如果是多POJO操作,就要有多行代码 */
		int id = this.dynastyDao.saveOneDao(dynasty);
		return id ; 
	}

	@Override
	public void updateOneDynastyService(Dynasty dynasty)
	{
		this.dynastyDao.updateOneDao(dynasty);
	}

	@Override
	public void deleteOneDynastyService(Dynasty dynasty)
	{
		this.dynastyDao.deleteOneDao(dynasty);
	}

	@Override
	public List<Dynasty> selectListDynastyService()
	{
		/* 写完Dao以后,一定要写Service
		 * 否则在Test执行的时候是空的
		 *  */
		return this.dynastyDao.selectListDao();
	}
	@Override
	public Dynasty selectOneDynastyService(Map<String, Object> condMap)
	{
		return this.dynastyDao.selectOneDao(condMap);
	}

	@Override
	public String printTitleDynastyService()
	{
		String result = "id\t名字\t首都\t年龄\t开国时间\t\t\t创建时间\t\t\t更新时间";
		return result;
	}

	
	@Override
	public int saveOneHuLuWaService(HuLuWa huluwa)
	{
		int id = this.huluwaDao.saveOneDao(huluwa);
		return id;
	}

	@Override
	public void updateOneHuLuWaService(HuLuWa huluwa)
	{
		this.huluwaDao.updateOneDao(huluwa);
		
	}

	@Override
	public void deleOneHuLuWaService(HuLuWa huluwa)
	{
		this.huluwaDao.deleteOneDao(huluwa);
		
	}

	@Override
	public List<HuLuWa> selectListHuLuWaService()
	{
		List<HuLuWa> huluwalist = this.huluwaDao.selectListDao();
		Map<String, Object> condMap = new HashMap<String,Object>();
		for (int i = 0; i <huluwalist.size(); i++)
		{
			HuLuWa huluwa = huluwalist.get(i);
			condMap.put("id",huluwa.getIdDynasty());
			Dynasty dynasty = this.selectOneDynastyService(condMap);
			huluwa.setDynasty(dynasty);
		}
		return huluwalist;
	}

	@Override
	public HuLuWa selectOneHuLuWaService(Map<String, Object> condMap)
	{
		
		return this.huluwaDao.selectOneDao(condMap);
	}

	@Override
	public String printTitleHuLuWaService()
	{
		String result = "id\t名字\t编号\t年龄\t\t创建时间\t\t\t更新时间";
		return result;
	}

	
	}

	
	

	

	



